package org.github.xhjcehust.dubbo.proxy.config;

import cn.htd.center.business.user.service.UserExportApi;
import cn.htd.center.business.user.service.UserLoginApi;
import cn.htd.center.central.user.service.CusUserService;
import cn.htd.usercenter.service.UserExportService;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.rpc.service.GenericService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

@Component
public class InitProject implements ApplicationRunner {

    private Logger logger = LoggerFactory.getLogger(InitProject.class);

//    @Reference(version="${dubbo.registry.version.dev}",registry = "${dubbo.registry.address.dev}")
//    private UserLoginApi userLoginApiDev;
//    @Reference(version="${dubbo.registry.version.fat}",registry = "${dubbo.registry.address.fat}")
//    private UserLoginApi userLoginApiFat;
//    @Reference(version="${dubbo.registry.version.dev4}",registry = "${dubbo.registry.address.dev4}")
//    private UserLoginApi userLoginApiDev4;
//    @Reference(version="${dubbo.registry.version.dev}",registry = "${dubbo.registry.address.dev}")
//    private UserExportService userExportServiceDev;
//    @Reference(version="${dubbo.registry.version.fat}",registry = "${dubbo.registry.address.fat}")
//    private UserExportService userExportServiceFat;
//    @Reference(version="${dubbo.registry.version.dev4}",registry = "${dubbo.registry.address.dev4}")
//    private UserExportService userExportServiceDev4;
//    @Reference(version="${dubbo.registry.version.dev}",registry = "${dubbo.registry.address.dev}")
//    private CusUserService cusUserServiceDev;
//    @Reference(version="${dubbo.registry.version.fat}",registry = "${dubbo.registry.address.fat}")
//    private CusUserService cusUserServiceFat;
//    @Reference(version="${dubbo.registry.version.dev4}",registry = "${dubbo.registry.address.dev4}")
//    private CusUserService cusUserServiceDev4;

//    @Reference(registry = "dev",version="${dubbo.registry.version.dev}")
//    private UserLoginApi userLoginApiDev;
//    @Reference(registry = "${dubbo.registries.dev4.address}",version="${dubbo.registry.version.dev4}")
//    private UserLoginApi userLoginApiDev4;

//    @Value("${dubbo.application.name}")
//    private String appName;
//    @Value("${dubbo.registry.version.dev}")
//    private String versionDev;
//    @Value("${dubbo.registry.address.dev}")
//    private String addrDev;


    @Override
    public void run(ApplicationArguments applicationArguments) throws Exception {
        logger.info("InitProject.run开始");

//        lauchDubbo(versionDev,addrDev,UserLoginApi.class);
//        lauchDubbo(versionDev,addrDev,UserExportService.class);
//        lauchDubbo(versionDev,addrDev,CusUserService.class);

        logger.info("InitProject.run结束");
    }

//    private void lauchDubbo(String version,String address,Class cls){
//        ReferenceConfig<GenericService> reference = new ReferenceConfig<>();
//        reference.setApplication(new ApplicationConfig(appName));
//
//        reference.setInterface(cls);
//        reference.setVersion(version);
//        reference.setGeneric(true);
////            reference.setId(param.getId());
//        reference.setTimeout(60000);
//        reference.setRetries(0);
//
//        RegistryConfig registry = new RegistryConfig();
//        registry.setAddress(address);
//        reference.setRegistry(registry);
//
//        GenericService genericService = reference.get();
//    }
}
